package siddur.traktask.chrome.controller;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttributes;

import siddur.traktask.chrome.model.HourData;
import siddur.traktask.chrome.model.ScreenShotData;
import siddur.traktask.facade.TrakFacade;
import siddur.traktask.framework.Constants;
import siddur.traktask.repository.JobRepository;

@RestController
@RequestMapping("/trakapi")
@SessionAttributes(Constants.SESSION_USER)
public class TrakAPIController {

	@PersistenceContext
	private EntityManager em;
	
	@Autowired JobRepository jobRep;
	
	@Autowired TrakFacade trakFacade;
	
	
	@RequestMapping(value="screenshot", method=RequestMethod.POST)
	public int saveScreenShot(@RequestBody List<ScreenShotData> data){
		trakFacade.saveScreenShot(data);
		return 1;
	}
	
	@RequestMapping(value="hour", method=RequestMethod.POST)
	public int saveHour(@RequestBody List<HourData> data){
		trakFacade.saveHour(data);
		return 1;
	}
	
	@RequestMapping(value="memo", method=RequestMethod.POST)
	public int saveMemo(@RequestBody List<HourData> data){
		trakFacade.saveMemo(data);
		return 1;
	}
}
